package com.chaowen.yixin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.chaowen.yixin.InputMethodRelativeLayout.OnSizeChangedListenner;

/**
 * 
 * @author junjun
 * 
 */
public class MainLoginActivity extends Activity implements OnSizeChangedListenner, OnClickListener {

	private InputMethodRelativeLayout layout;
	private LinearLayout boot;
	private LinearLayout login_logo_layout_h;
	private LinearLayout login_logo_layout_v;
	private Button loginButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_login);
		// 取得InputMethodRelativeLayout组件
		layout = (InputMethodRelativeLayout) this.findViewById(R.id.loginpage);
		// 设置监听事件
		layout.setOnSizeChangedListenner(this);
		// 取得大LOGO布局
		login_logo_layout_v = (LinearLayout) this.findViewById(R.id.login_logo_layout_v);
		// 取得小LOGO布局
		login_logo_layout_h = (LinearLayout) this.findViewById(R.id.login_logo_layout_h);

		// 取得找回密码和新注册布局
		boot = (LinearLayout) this.findViewById(R.id.reg_and_forget_password_layout);

		loginButton = (Button) this.findViewById(R.id.login_btn);
		loginButton.setOnClickListener(this);
	}

	/**
	 * 在Activity中实现OnSizeChangedListener，原理是设置该布局的paddingTop属性来控制子View的偏移
	 */
	@Override
	public void onSizeChange(boolean flag, int w, int h) {
		if (flag) {// 键盘弹出时
			layout.setPadding(0, -10, 0, 0);
			boot.setVisibility(View.GONE);
			login_logo_layout_v.setVisibility(View.GONE);
			login_logo_layout_h.setVisibility(View.VISIBLE);
		} else { // 键盘隐藏时
			layout.setPadding(0, 0, 0, 0);
			boot.setVisibility(View.VISIBLE);
			login_logo_layout_v.setVisibility(View.VISIBLE);
			login_logo_layout_h.setVisibility(View.GONE);
		}
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.login_btn: // 登录点击事件
			intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.yixinBtnLayout: // 注册的点击事件
			break;
		default:
			break;
		}

	}

}
